<?php

/**
 * MensajeAlerta form.
 *
 * @package    cronos-doctrine
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class MensajeAlertaForm extends BaseMensajeAlertaForm
{
  public function configure()
  {
   //Eliminar los campos del formularios  created_at y updated_at
      unset (
        $this['created_at'],
        $this['updated_at']

      );
      
      $this->widgetSchema['empresa_id'] = new sfWidgetFormInputHidden(array(),array('value'=> sfContext::getInstance()->getUser()->getAttribute('agente_user_empresa_id')));
      $this->widgetSchema['padre_id'] =  new sfWidgetFormInputHidden();
      $this->widgetSchema['operador_para_id'] =  new sfWidgetFormInputHidden();
      $this->widgetSchema['operador_para_id2'] = new sfWidgetFormDoctrineChoice(array(
         'multiple' => true, 
         'model' => 'sfGuardUser',
         'query' => $this->getObject()->getOperadorDe()->getTable()->getAgentes($this->getObject()->getOperadorDeId()),
         'expanded' => true));
      
      $this->validatorSchema['operador_para_id2'] = new sfValidatorPass();
      
      //Usuario Recordatorio
      $recordatorios = $this->getObject()->getRecordatorio();
      
      if(!count($recordatorios)) {
          $recordatorios = array();
      }     
      
      $recordatorios_form = new sfForm();
      $count = 0;
      
      if($this->isNew()){
          
           
      }else {

        foreach ($recordatorios as $recordatorio){
            $recor_form = new RecordatorioForm($email);
            $recordatorios_form->embedForm($count, $recor_form);
            $count++;
             
      } }
      $this->embedForm('recordatorios', $recordatorios_form);
      // Fin Recordatorio
  }
  
  public function addRecordatorio($num) {
      $recordatorio = new Recordatorio();
      $recordatorio->setMensajeAlerta($this->getObject());
      $recordatorio_form = new RecordatorioForm($recordatorio);
      
      $this->embeddedForms['recordatorios']->embedForm($num, $recordatorio_form);
      $this->embedForm('recordatorios', $this->embeddedForms['recordatorios']);
      
  }
  
  public function  bind(array $taintedValues = null, array $taintedFiles = null) {

    //$this->getEmbeddedForm('Comun')->bind($taintedValues, $taintedFiles);
      
    if(isset($taintedValues['recordatorios'])){
       
        foreach ($taintedValues['recordatorios'] as $key => $newPre)
        {
            if(!isset ($this['recordatorios'][$key])){
                $this->addRecordatorio($key);
            }
        }
    }
    
     parent::bind($taintedValues, $taintedFiles);
    }
}
